// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

const db = cloud.database()
const _ = db.command
const todos = db.collection('list_data')

// 云函数入口函数
exports.main = async (event, context) => {
  let allData = []
  let hasMore = true
  let limit = 5 // 每次查询的数量，根据实际情况调整
  let offset = 0

  while (hasMore) {
    const shopData = await todos.skip(offset).limit(limit).get()

    if (shopData.data.length === 0) {
      hasMore = false
    } else {
      allData = [...allData, ...shopData.data]
      offset += limit
    }
  }

  return allData
 
}